package socket;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server1 {

	public static void main(String[] args) {
		try {
			System.out.println("server....");
			ServerSocket serverSocket = new ServerSocket(6666);
			System.out.println("server------client");
			Socket socket = serverSocket.accept();
			
			BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			BufferedWriter output = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
			
			Scanner sc = new Scanner(System.in);
			boolean should = true;
			String clientMsg;
			String serverMsg;
			while(should) {
				clientMsg = input.readLine();
				System.out.println("client: "+clientMsg);
				
				System.out.println("input as serer...");
				serverMsg = sc.nextLine();
				System.out.println("server: "+serverMsg);
				output.write(serverMsg + "\r");
				output.flush();
				
				if("bye".equals(clientMsg)||"bye".equals(serverMsg)) {					
				    should = false;
		        }
			}
			sc.close();
			socket.close();
			serverSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}


	}

}
